﻿var status = 0;
var icon = "#fUI/Basic.img/BtMin2/normal/0#";
var iconX = "#fEffect/CharacterEff/1112905/0/1#";
var iconStar = "#fEffect/CharacterEff/1112904/2/1#";
var icon1 = "#fEffect/CharacterEff/1042176/0/0#";
var iconHR = "#fEffect/CharacterEff/1082565/0/0#"
var icon2 = "#fEffect/CharacterEff/1082565/2/0#";
var icon3 = "#fEffect/CharacterEff/1082565/4/0#";
var icon4 = "#fUI/UIWindow2.img/QuestAlarm/BtQ/normal/0#";
var giftContent = Array(
 Array("勋章神秘铁砧",   250, Array(
        Array(5062402, 1)
    )),
 Array("神秘力量勋章(含三枚)",   300, Array(
        Array(2430026, 1)
    )),
 Array("神秘力量升级材料(1)",   40, Array(
        Array(1712000, 1)
    )),
 Array("戴米安机器人兑换卷(三潜)",   850, Array(
        Array(2435482, 1)
    )),
 Array("阿丽莎机器人兑换卷(三潜)",   850, Array(
        Array(2435483, 1)
    )),
 Array("隐月(女)兑换卷(三潜)",   850, Array(
        Array(2432342, 1)
    )),
 Array("斯乌机器人兑换卷(三潜)",   850, Array(
        Array(2433167, 1)
    )),
 Array("奥尔卡机器人兑换卷(三潜)",   850, Array(
        Array(2433339, 1)
    )),
 //Array("完美饰品防具卷轴 X 1", 40, Array(
       // Array(2616051, 1)
    //)),
 //Array("完美饰品防具卷轴 X 10", 400, Array(
       // Array(2616051, 10)
    //)),
 Array("专属紫金枫叶羽毛 X 1", 1000, Array(
        Array(2570002, 1)
    )),

 Array("17星星之力强化卷",   100, Array(
        Array(2049371, 1)
    )),
 Array("18星星之力强化卷",   200, Array(
        Array(2049387, 1)
    )),
 Array("19星星之力强化卷",   400, Array(
        Array(2049388, 1)
    )),
 Array("20星星之力强化卷",   600, Array(
        Array(2049389, 1)
    )),
  Array("玛瑙戒指礼包1",   100, Array(
        Array(2433444, 1)
    )),
  Array("玛瑙戒指礼包2",   150, Array(
        Array(2435087, 1)
    )),
  Array("玛瑙戒指礼包3",   300, Array(
        Array(2434174, 1)
    )),
  Array("彩色枫叶",   600, Array(
        Array(4032733, 1)
    )),
 Array("超越套装",   500, Array(
        Array(2431303, 1)
    )),
  Array("闪炫魔方 X 50",   900, Array(
        Array(5062024, 50)
    )),
  Array("核心宝石 X 100",   45, Array(
        Array(2435719, 100)
    )),
  Array("探险之黑暗暴击戒指",   200, Array(
        Array(1113069, 1)
    )),
 Array("遗忘之神话耳环",   300, Array(
        Array(1032219, 1)
    )),
  Array("法弗纳武器箱（自选)",   300, Array(
        Array(2431509, 1)
    )),
  Array("法弗纳防具箱（自选)",   500, Array(
        Array(2431988, 1)
    )),
	Array("埃苏武器箱（自选)",   700, Array(
        Array(2434340, 1)
    )),
	Array("诺巴战士套装",   100, Array(
       Array(1132169, 1),
        Array(1102476, 1),
        Array(1072737, 1)
    )), 
    Array("诺巴魔法师套装",   100, Array(
        Array(1132170, 1),
        Array(1102477, 1),
        Array(1072738, 1)
    )), 
    Array("诺巴弓箭手套装",   100, Array(
        Array(1132171, 1),
        Array(1102478, 1),
        Array(1072739, 1)
    )),
    Array("诺巴飞侠套装",     200, Array(
        Array(1132172, 1),
        Array(1102479, 1),
        Array(1072740, 1)
    )),
    Array("诺巴海盗套装",  100, Array(
        Array(1132173, 1),
        Array(1102480, 1),
        Array(1072741, 1)
    )),
     Array("8周年点点红",   95, Array(
        Array(1012319, 1)
    )),
	Array("进击巨人勋章",   120, Array(
        Array(1142788, 1)
    )),
	Array("人类最强勋章",   150, Array(
        Array(1142789, 1)
    )),
    // Array("本F最强套装：漩涡套装",   500, Array(
      //  Array(1003976, 1),
      //  Array(1102623, 1),
      //  Array(1082556, 1),
     //   Array(1052669, 1),
     //   Array(1072870, 1),
     //   Array(2610003, 10),
    //    Array(-1, 150000)
   // )),
    //  Array("最高级贝勒德首饰",   300, Array(
     //   Array(1113075, 1),
     //   Array(1032223, 1),
     //   Array(1122267, 1),
      //  Array(1132246, 1),
      //  Array(-1, 50000)
   // ))
   Array("古董品图腾套装",   500, Array(
        Array(1202173, 1),
		Array(1202174, 1),
		Array(1202175, 1)
    )), 
   //Array("奥尔卡的徽章(解除状态加5%G)",   300, Array(
   //     Array(1182158, 1)
    //)), 
	//Array("MX-131徽章(加一次段数)",   300, Array(
    //    Array(1182136, 1)
    //)), 
	Array("高级次元手套",   100, Array(
        Array(1082489, 1)
    )), 

	Array("恐怖鬼娃的伤口（50G）",   200, Array(
        Array(1012174, 1)
    )), 
	Array("星星X5000",   30, Array(
        Array(4001839, 5000)
    )), 
	Array("咒语痕迹X5000",   20, Array(
        Array(4001832, 5000)
    )), 
	Array("暴风手套攻击卷X10",   50, Array(
        Array(2040874, 10)
    )), 
	Array("暴风手套魔力卷X10",   50, Array(
        Array(2040875, 10)
    )), 

     Array("战神祝福戒指",   350, Array(
        Array(1113020, 1)
    )), 
    Array("黑龙传说指环(每个角色限购一次)",   350, Array(
        Array(1113084, 1)
    )), 
    Array("独眼巨人之眼Lv.3",   100, Array(
        Array(1022226, 1)
    )),
    Array("阿丽莎之光辉",     450, Array(
        Array(1382235, 1)
    )),
    Array("进阶贝伦头盔",  120, Array(
        Array(1003722, 1)
    )),
    Array("解放的凯瑟利安",  450, Array(
        Array(1402180, 1)
    )),
	Array("校长织田徽章",  80, Array(
        Array(1162035, 1)
    )),
	Array("真·本多忠胜图腾",  150, Array(
        Array(1202090, 1)
    )),
	Array("真·上杉谦信图腾",  150, Array(
        Array(1202091, 1)
    )),
	Array("真·真田幸村图腾",  150, Array(
        Array(1202089, 1)
    )),
	Array("战斗机器人(女)",  300, Array(
        Array(1662072, 1)
    )),
	Array("战斗机器人(男)",  300, Array(
        Array(1662073, 1)
    )),
	Array("南哈特机器人(男)",  400, Array(
        Array(1662064, 1)
    )),
	Array("伊尔卡机器人(男)",  400, Array(
        Array(1662065, 1)
    )),
	Array("希纳斯机器人(女)",  400, Array(
        Array(1662066, 1)
    )),
	Array("戴米安机器人",  450, Array(
        Array(1662088, 1)
    )),
	Array("阿丽莎机器人",  450, Array(
        Array(1662089, 1)
    )),
	Array("斯乌机器人",  450, Array(
        Array(1662092, 1)
    )),
	Array("奥尔卡机器人",  450, Array(
        Array(1662093, 1)
    )),
	Array("路西德机器人",  500, Array(
        Array(1662111, 1)
    )),
	Array("未来机器人(男)",  300, Array(
        Array(1662033, 1)
    )),
	Array("未来机器人(女)",  300, Array(
        Array(1662034, 1)
    )),
	Array("极真锂心脏",  300, Array(
        Array(1672027, 1)
    )),
	Array("V卷轴自选（1张）",  55, Array(
        Array(2435413, 1)
    )),
	Array("X卷轴自选（1张）",  20, Array(
        Array(2434666, 1)
    )),
	Array("X卷轴自选（10张）",  200, Array(
        Array(2431042, 1)
    )),
	Array("惊人武器卷轴自选（1张）",  10, Array(
        Array(2431744, 1)
    )),
	Array("未来机器人心脏 : 最高级",  200, Array(
        Array(1672039, 1)
    )),
	//Array("高级智能机器人(男)",  200, Array(
    //    Array(1662002, 1)
    //)),
	//Array("高级智能机器人(女)",  200, Array(
   //     Array(1662003, 1)
   // )),
	Array("真·觉醒冒险之心（自选）",  200, Array(
        Array(2431996, 1)
    )),
	Array("稀有外星碎片头盔",  300, Array(
        Array(1003893, 1)
    ))
   // Array("鲁塔比斯魔法师套装", 398, Array(
   //     Array(1003798, 1),
   //     Array(1042255, 1),
   //     Array(1062166, 1)
   // )),
   // Array("鲁塔比斯弓箭手套装", 398, Array(
   //    Array(1003799, 1),
   //     Array(1042256, 1),
   //     Array(1062167, 1)
    //)),
    //Array("鲁塔比斯飞侠套装", 398, Array(
   //     Array(1003800, 1),
   //     Array(1042257, 1),
   //     Array(1062168, 1)
   // )),
    //  Array("封印解除卷轴X10", 10, Array(
    //    Array(2610001, 10),
    //    Array(-1, 2500)
   // ))
    //Array("蜡笔礼包", 500, Array(
        //Array(3994417, 1),
        //Array(3994418, 1),
        //Array(3994419, 1),
        //Array(3994420, 1),
        //Array(3994421, 1),
        //Array(3994422, 1)
    //))
);
var giftId = -1;
var gifts = null;
var price = 999;
var column = new Array("装备", "消耗", "设置", "其他", "商城");
function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (status == 0 && mode == 0) {
        cm.dispose();
        return;
    }
    if (mode == 1) {
        status++;
    } else {
        status--;
    }
    if (status == 0) {
		var conn = cm.getConnection();
		var pstmt = conn.prepareStatement("select leiji from hypay where accname = '"+cm.getC().getAccountName()+"'");
		var result = pstmt.executeQuery();
		result.next();
		var revenue = result.getString("leiji");
        var text = "";
		text = ""+iconHR+"尊敬的玩家#b#h ##k，欢迎来到#b#eVIP商城，点击可以查看礼包内容哦！#n#k\r\n";
        //text += "#e#b欢迎来到VIP商城，点击可以查看礼包内容哦！\r\n";
		text += ""+icon2+"您当前余额为：#r"+cm.getHyPay(1)+"#k "+"\t\t"+icon2+"累计充值：#r"+revenue+"#k\r\n";
        for(var key in giftContent) {
            text+="#b#L"+key+"#购买【#r#e"+giftContent[key][0]+"#n#b】 #e#d需要"+giftContent[key][1]+"余额#n#b#l#k\r\n";
        }
        cm.sendSimple(text);
    } else if (status == 1) {
        giftId = parseInt(selection);
        price = giftContent[giftId][1];
        gifts = giftContent[giftId][2];
        var text="#r#e"+giftContent[giftId][0]+"#n#b内容：\r\n";
        for(var key in gifts) {
            var itemId = gifts[key][0];
            var itemQuantity = gifts[key][1];
            text+="#i"+itemId+":##b" + (itemId == -1 ? "赠送点券" : "#z" + itemId + "#") + "#k #rx "+itemQuantity+"#k\r\n";
        }
        text+="\r\n#d是否花费#e#r"+price+"#n#d余额购买该礼包？#k";
        cm.sendYesNo(text);
    } else if (status == 2) {
        if (giftId!=-1 && gifts != null) {
            var needslot = new Array(0, 0, 0, 0, 0);
            for (var i in gifts) {
                var type = Math.floor(gifts[i][0] / 1000000);
                if (type == -1) {
                    continue;
                }
                needslot[type - 1] = needslot[type - 1] + 1;
            }
            for (var i = 0; i < 5; i++) {
                if (cm.getSpace(i + 1) < needslot[i]) {
                    cm.sendOk("您的" + column[i] + "栏位空间不足" + needslot[i] + "格，请清理后再来。");
                    cm.dispose();
                    return;
                }
            }
            if (cm.getHyPay(1) < price) {
                cm.sendOk("您的余额不足，请先充值后再购买。");
                cm.dispose();
                return ;
            }
            for(var key in gifts) {
                var itemId = gifts[key][0];
                var itemQuantity = gifts[key][1];
                if (itemId == -1) {
                    cm.gainNX(itemQuantity);
                } else {
                    cm.gainGachaponItem(itemId, itemQuantity,"VIP商城",3);
                }
            }
            cm.addHyPay(price);
            cm.sendOk("恭喜您，购买成功！");
			//cm.worldSpouseMessage(0x0F,"[VIP商城] VIP玩家 "+ cm.getChar().getName() +" 从商城里掏走了价值"+price+"的["+giftContent[giftId][0]+"]装备！！！");
            cm.dispose();
        } else {
            cm.sendOk("购买错误！请联系管理员！");
            cm.dispose();
        }
    }
}